/**
 * model 池
 */
import { queryArray } from './share';

class ModelFactory {
  constructor() {
    this.app = null;
    this.models = [];
  }
  init(app) {
    this.app = app;
    this.models = app._models;
  }
  getModel(name) {
    let model = queryArray(this.models, name, 'namespace');
    if (!model) {
      model = queryArray(this.app._models, name, 'namespace');
      model && this.models.push(model);
    }
    return model;
  }
}
const service = new ModelFactory();
export default service;
